﻿export default {
  props: ['formItemConfig'],
  data () {
    return {
      currentSeriesIndex: 0
    }
  },
  methods: {
    // 移除当前列
    handleOptionsRemove (index) {
      if (this.formItemConfig.type === 'grid') {
        this.formItemConfig.columns.splice(index, 1)
      } else if (this.formItemConfig.type === 'table') {
        this.formItemConfig.tableColumn.splice(index, 1)
      } else if (this.formItemConfig.type === 'tabs') {
        this.formItemConfig.tabList.splice(index, 1)
      }
    },
    // 添加列
    handleAddColumn () {
      this.formItemConfig.columns.push({
        span: 1,
        list: []
      })
    },
    // 添加tabs
    handleAddOption () {
      this.formItemConfig.tabList.push({
        label: '新增tab页名称',
        list: []
      })
    },
    // 栅格的内容区域值改变时
    gridSpanChange () {
      if (this.formItemConfig && this.formItemConfig !== {} && this.formItemConfig.type === 'grid') {
        let hadEcharts = false
        for (let i = 0; i < this.formItemConfig.columns.length; i++) {
          for (let t = 0; t < this.formItemConfig.columns[i].list.length; t++) {
            if (this.formItemConfig.columns[i].list[t].type.indexOf('echarts_') !== -1) {
              hadEcharts = true
              break
            }
          }
          if (hadEcharts) {
            break
          }
        }
        if (hadEcharts) {
          this.$store.dispatch('updateSizeMethod', this.$store.state.updateSize + 1)
        }
      }
    },
    // 是否为条形柱状图
    barTypeChange () {
      if (this.formItemConfig.isVerticalBar) {
        this.formItemConfig.dataOptions.xAxis.type = 'value'
        this.formItemConfig.dataOptions.yAxis.type = 'category'
      } else {
        this.formItemConfig.dataOptions.xAxis.type = 'category'
        this.formItemConfig.dataOptions.yAxis.type = 'value'
      }
    }
  },
  watch: {
    // 选中的元素变化时
    'formItemConfig.model': {
      handler: function (val, oldVal) {
        this.currentSeriesIndex = 0
      },
      deep: true
    }
  }
}
